package version3.part2.Server.netty.nettyInitializer;


import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import lombok.AllArgsConstructor;
import version3.part2.Server.netty.handler.NettyRPCServerHandler;
import version3.part2.Server.provider.ServiceProvider;
import version3.part2.common.serializer.MyCode.MyDecoder;
import version3.part2.common.serializer.MyCode.MyEncoder;
import version3.part2.common.serializer.MySerializer.impl.JSONSerializer;


@AllArgsConstructor
public class NettyServerInitializer extends ChannelInitializer<SocketChannel> {
    private ServiceProvider serviceProvider;
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new MyDecoder());
        pipeline.addLast(new MyEncoder(new JSONSerializer()));
        pipeline.addLast(new NettyRPCServerHandler(serviceProvider));
    }
}
